package com.ywjt.platformbusiness.home.activity;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.inputmethod.EditorInfo;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.ywjt.platformbusiness.R;
import com.ywjt.platformbusiness.base.BaseActivity;
import com.ywjt.platformbusiness.base.MyApp;
import com.ywjt.platformbusiness.util.SPUtils;
import com.ywjt.platformbusiness.util.SoftKeyboardUtils;
import com.ywjt.platformbusiness.widget.FlowViewGroup;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class ActivityCitySelect extends BaseActivity implements View.OnClickListener {
    private EditText etSearch;
    private String keys="";

    public static void actionStart(Context context) {
        Intent intent = new Intent(context, ActivityCitySelect.class);
        context.startActivity(intent);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.ivBack:
                finish();
                break;

            case R.id.tvSearch:
                SoftKeyboardUtils.hideSoftKeyboard(this);
                if(SPUtils.getSharedBooleanData(getContext(),"isLogin")){
                    if(keys.equals("")||keys.length()==0){
                        //搜索内容为空
                        Toast.makeText(getContext(),"搜索内容不能为空",Toast.LENGTH_SHORT).show();
                    }else {
                       // Activity_Search.actionStart(getContext(),keys);
                    }
                }else {
                    Toast.makeText(getContext(),"你还没有登录请先去登录",Toast.LENGTH_SHORT).show();
                }
                break;
        }
    }

    @Override
    protected void init(Bundle savedInstanceState) {
        setAndroidNativeLightStatusBar(true);
    }

    @Override
    protected int setLayoutResourceID() {
        return R.layout.activity_cityselect;
    }

    @Override
    protected void initView() {
        setTitleText("城市选择");
        etSearch=findViewById(R.id.etSearch);
        etSearch.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
                try {
                    keys = charSequence.toString().trim();
                } catch (Exception e) {
                    keys = "";
                }
            }

            @Override
            public void afterTextChanged(Editable editable) {

            }
        });
        etSearch.setOnEditorActionListener(new TextView.OnEditorActionListener() {
            @Override
            public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
                if (i == EditorInfo.IME_ACTION_SEARCH) {
                    if(SPUtils.getSharedBooleanData(getContext(),"isLogin")){
                        if(keys.equals("")||keys.length()==0){
                            //搜索内容为空
                            Toast.makeText(getContext(),"搜索内容不能为空",Toast.LENGTH_SHORT).show();
                        }else {
                           // saveSearchHistory(keys);
                           // Activity_Search.actionStart(getContext(),keys);
                        }
                    }else {
                        Toast.makeText(getContext(),"你还没有登录请先去登录",Toast.LENGTH_SHORT).show();
                    }
                    return true;
                }
                return false;

            }});
    }


    @Override
    protected void initData() {
    }

    @Override
    protected int getTitleBarType() {
        return 0;
    }
}
